#-*-coding:utf-8-*-
# 时间:2019/8/29
# 作者:zfh
import os
import codecs
import configparser
# 获取当前路径
proDir = os.path.split(os.path.realpath(__file__))[0]
# 获取配置文件路径
configPath = os.path.join(proDir, "config.ini")


class ReadConfig:
    def __init__(self):
        # 先打开文件，查看开头是否有空格
        fd = open(configPath)
        data = fd.read()
        # 如果包含空格，则去掉空格
        if data[:3] == codecs.BOM_UTF8:
            data = data[3:]
            file = codecs.open(configPath, "w")
            file.write(data)
            file.close()
        fd.close()
        # 读取配置文件
        self.cf = configparser.ConfigParser()
        self.cf.read(configPath)

    # def get_excelDir(self, name):
    #     value = self.cf.get("EXCELDIR", name)
    #     return value

    def get_http(self, name):
        value = self.cf.get("HTTP", name)
        return value

    def get_cookies(self, name):
        value = self.cf.get("COOKIES", name)
        return value

    def set_cookies(self,name, value):
        # 写入token值
        self.cf.set("COOKIES", name, value)
        self.cf.write(open(configPath,'w'))
